//
//  FZQMainViewController.swift
//  FZQSinLangWeiBo
//
//  Created by fuzhiqiang on 17/1/16.
//  Copyright © 2017年 fzq. All rights reserved.
//

import UIKit

class FZQMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
       //实例化自定义的tabbar
        let tabbar = FZQTabBar()
        //通过kvc 给只读属性赋值
        setValue(tabbar, forKey: "tabBar")
        //2.实例化闭包
        tabbar.colsure = {
            //4闭包回调
            print("监听到了按钮的点击")
        }
        //首页
        addchildViewController(FZQHomeViewController(), title: "首页", imgName: "tabbar_home")
        //消息
        addchildViewController(FZQMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        //发现
        addchildViewController(FZQDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        //我
        addchildViewController(FZQProfileViewController(), title: "我", imgName: "tabbar_profile")
       }
}
  //extension相当于oc中的分类，可以添加属性与方法
extension FZQMainViewController {
        func addchildViewController(_ childController: UIViewController,title: String,imgName: String) {
           childController.title = title
           //设置title颜色
            childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: FZQThemeColor], for: UIControlState.selected)
            //设置img,withRenderingMode(UIImageRenderingMode.alwaysOriginal)使用图片本身的颜色
            childController.tabBarItem.image = UIImage(named:imgName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
            //高亮
            childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
            
            //添加子控制器
            addChildViewController(FZQNavigationControlle(rootViewController: childController))
        }
    }



